package com.ruoyi.robot.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.robot.domain.ChatRobotSetting;
import com.ruoyi.robot.service.IChatRobotSettingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机器人设置Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/robot/setting")
public class ChatRobotSettingController extends BaseController
{
    @Autowired
    private IChatRobotSettingService chatRobotSettingService;


    /**
     * 查询机器人设置列表
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatRobotSetting chatRobotSetting)
    {
        startPage();
        List<ChatRobotSetting> list = chatRobotSettingService.selectChatRobotSettingList(chatRobotSetting);
        return getDataTable(list);
    }

    /**
     * 导出机器人设置列表
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:export')")
    @Log(title = "机器人设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatRobotSetting chatRobotSetting)
    {
        List<ChatRobotSetting> list = chatRobotSettingService.selectChatRobotSettingList(chatRobotSetting);
        ExcelUtil<ChatRobotSetting> util = new ExcelUtil<ChatRobotSetting>(ChatRobotSetting.class);
        util.exportExcel(response, list, "机器人设置数据");
    }

    /**
     * 获取机器人设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(chatRobotSettingService.selectChatRobotSettingByUserId(userId));
    }

    /**
     * 新增机器人设置
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:add')")
    @Log(title = "机器人设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatRobotSetting chatRobotSetting)
    {
        return toAjax(chatRobotSettingService.insertChatRobotSetting(chatRobotSetting));
    }

    /**
     * 修改机器人设置
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:edit')")
    @Log(title = "机器人设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatRobotSetting chatRobotSetting)
    {
        return toAjax(chatRobotSettingService.updateChatRobotSetting(chatRobotSetting));
    }

    /**
     * 删除机器人设置
     */
    @PreAuthorize("@ss.hasPermi('robot:setting:remove')")
    @Log(title = "机器人设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(chatRobotSettingService.deleteChatRobotSettingByUserIds(userIds));
    }
}
